<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="用户编号" align="center" key="id" prop="id" v-if="columns[0].visible" />
          <el-table-column label="姓名" align="center" key="name" prop="name" v-if="columns[2].visible" :show-overflow-tooltip="true" />
          <el-table-column label="用户昵称" align="center" key="nickname" prop="nickname" v-if="columns[3].visible" :show-overflow-tooltip="true" />
          <el-table-column label="年龄" align="center" key="age" prop="age" v-if="columns[4].visible" :show-overflow-tooltip="true" />
          <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[5].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.crtTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="微信号" align="center" key="wechat" prop="wechat" v-if="columns[6].visible" :show-overflow-tooltip="true" />
          <el-table-column
            align="center"
            label="二维码"
            width="90px"
            key="headimgurl"
            prop="headimgurl"
            v-if="columns[7].visible"
          >
            <template slot-scope="scope">
              <ImagePreview :src="scope.row.qrcode" :width="50" :height="50"/>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="个性图片"
            width="90px"
            key="images"
            prop="images"
            v-if="columns[8].visible"
          >
            <template slot-scope="scope">
              <ImagePreview  :src="scope.row.images[0]" :width="50" :height="50"/>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="detailShow(scope.row)"
              >详细信息</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <!--查看详情-->
    <el-dialog
      title="详细信息"
      :visible.sync="isDetail"
      width="60%">
      <el-descriptions class="margin-top" :column="3" size="medium" border>
        <el-descriptions-item>
          <template slot="label">
            用户ID
          </template>
          {{ detail.id }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            用户姓名
          </template>
          {{ detail.name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            昵称
          </template>
          {{ detail.nickname }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            出生年份
          </template>
          {{ detail.age }}年
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            电话
          </template>
          {{ detail.mobile }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            体重
          </template>
          {{ detail.weight }}kg
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            婚姻状况
          </template>
          <dict-tag :options="dict.type.fire_user_marry" :value="detail.ismarry"/>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            工作信息
          </template>
          <dict-tag :options="dict.type.fire_user_job" :value="detail.job"/>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            星座
          </template>
          <dict-tag :options="dict.type.fire_user_constellation" :value="detail.constellation"/>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            微信号
          </template>
          {{ detail.wechat }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            身高
          </template>
          {{ detail.high }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            房产
          </template>
          <dict-tag :options="dict.type.fire_user_house" :value="detail.house"/>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            车产
          </template>
          <dict-tag :options="dict.type.fire_user_car" :value="detail.car"/>
        </el-descriptions-item>
        <el-descriptions-item :span="3">
          <template slot="label">
            个性照片
          </template>
          <div v-for="detail in detail.images" :key="detail" style="display: inline">
            <ImagePreview :src="detail" :width="50" :height="50"/>
          </div>
        </el-descriptions-item>
        <el-descriptions-item :span="3">
          <template slot="label">
            个人介绍
          </template>
          {{ detail.selfIntroduce }}
        </el-descriptions-item>
        <el-descriptions-item :span="3">
          <template slot="label">
            择偶标准
          </template>
          {{ detail.selectCriteria }}
        </el-descriptions-item>
      </el-descriptions>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="delSuggestList(detail)">取消推荐</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listUser, delUserIdFromSuggest } from './service'
export default {
  name: "suggest-list",
  dicts: [
    'fire_user_status',
    'fire_user_sex',
    'fire_user_marry',
    'fire_user_job',
    'fire_user_constellation',
    'fire_user_house',
    'fire_user_car'
  ],
  data() {
    return {
      // 详情
      detail: {},
      // 查看详情弹窗的显隐
      isDetail: false,
      // 日期范围
      dateRange: [],
      // 用户表格数据
      userList: null,
      // 总条数
      total: 0,
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 20
      },
      // 列信息
      columns: [
        { key: 0, label: `用户编号`, visible: true },
        { key: 1, label: `用户头像`, visible: true },
        { key: 2, label: `姓名`, visible: true },
        { key: 3, label: `用户昵称`, visible: true },
        { key: 4, label: `年龄`, visible: true },
        { key: 5, label: `创建时间`, visible: true },
        { key: 6, label: `微信号`, visible: true },
        { key: 7, label: `二维码`, visible: true },
        { key: 8, label: `个性图片`, visible: true },
      ]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询推荐用户列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then(response => {
          const { data: { resultList, totalPages} } = response;
          this.userList = resultList;
          this.total = totalPages;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log('selection', selection)
    },
    // 显示详情
    detailShow: function (obj) {
      this.detail = obj;
      this.isDetail = true;
    },
    // 取消推荐
    delSuggestList: function ({id}) {
      let _this = this;
      delUserIdFromSuggest({openid: id}).then(res => {
        if (res.data) {
          _this.getList();
          _this.isDetail = false;
          _this.$message({
            type: 'success',
            message: '删除推荐成功'
          });
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
